package com.woniu.user.controller;


import com.woniu.user.commons.Result;
import com.woniu.user.controller.form.RemarkForm;
import com.woniu.user.model.Remark;
import com.woniu.user.service.RemarkService;
import com.woniu.user.util.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/remark")
@Slf4j
public class RemarkController {

    @Resource
    private RemarkService remarkService;

    @PostMapping("add")
    public Result add(@RequestBody RemarkForm form, HttpServletRequest req){
        log.info("评价订单{}", form);
        Integer userId = JwtUtil.getUserIdFromReq(req);

        remarkService.add(userId, form);

        return Result.success(200, "评价成功", null);
    }

    @GetMapping("get")
    public Result get(Integer orderId, HttpServletRequest req){
        log.info("查看评价{}", orderId);
        Integer userId = JwtUtil.getUserIdFromReq(req);
        Remark remark = remarkService.get(userId, orderId);
        return Result.success(200, "查询成功", remark);
    }
}

